
import { SpriteFrame } from "cc";
import { Bonus } from "./Bonus";
import ResManager from "../common/ResManager";


export class ShopIng {
    /**当前商品索引 */
    typeId: number
    /**当前商品名称 */
    name: string
    /**当前商品价格 */
    price: string
    /**商品内容 */
    descMsg: string
    /**获得道具/元宝 0:获得道具 1:获得元宝 */
    index: number
    bonus: string
    type: number
    statck: number
    res: string
    markres: string
    discount: number
    extra: string
    times: string
    costtype: string
    desc: string

    /**
    * 根据配置的数据，来创建商城数据
    * @param arr 
    * @returns 
    */
    static createByShopIngObj(arr, i: number): ShopIng[] {
        let list: ShopIng[] = []
        for (let key in arr) {
            let v = new ShopIng()
            v.typeId = parseInt(key)
            v.name = arr[key].name
            v.type = arr[key].type
            v.descMsg = Bonus.bonusArrayDesc(arr[key].bonus)
            v.price = i == 0 ? Bonus.bonusArrayDesc(`${arr[key].costtype},0,${arr[key].price}`) : Bonus.bonusArrayDesc(`${arr[key].type},0,${arr[key].price}`)
            v.index = i
            list.push(v)
        };
        return list
    }

    async getShopIngImg():Promise<SpriteFrame>{
        if(this.type == 5){
            return ResManager.instance.loadAssetByUrl<SpriteFrame>(`shopImg/0/spriteFrame`)
        }

        return ResManager.instance.loadAssetByUrl<SpriteFrame>(`shopImg/${this.typeId}/spriteFrame`)
    }

}


